<?php
 function conn(){
   $hostname= "127.0.0.1";
   $dbuser = "sa";
   $dbpass = "root";
   $dbname = "hhyd_tris";
   $conn = mssql_pconnect($hostname,$dbuser,$dbpass) or die ("无法连接数据库");
   $i = mssql_select_db($dbname,$conn) or die ("无法连接数据库");
   mssql_select_db($dbname,$conn);
   }
 function import(){
       $this->ifLogin();//后台登录认证
       $this->hasLevel("+R");//发送调单调度权根
       $this->conn();
       $sql="select * from Requisition_Info where Requisition_ID like'2008%'" ;
       $result = mssql_query($sql);
       while ($res=mssql_fetch_assoc($result))  {
       $req_id1=mb_convert_encoding(trim($res['Requisition_ID']),"utf-8", "gb2312");
       $a1=str_replace(substr($req_id1,0,4),"", $req_id1);
       $req_id="云移红河分公司网调字【".substr($req_id1,0,4)."】". $a1."号";
       $org1_id="1";
       $us_login="lichaoying";
       $state="3";
       $type="1";
       $cell_id=str_replace(",","，",mb_convert_encoding(trim($res['Cell_ID']),"utf-8", "gb2312"));
       $mon="NULL";
       $main_send=str_replace(",","，",mb_convert_encoding(trim($res['Main_Send']),"utf-8", "gb2312"));
       $main_att=str_replace(",","，",mb_convert_encoding(trim($res['Main_attemper']),"utf-8", "gb2312"));
       $cause=str_replace(",","，",mb_convert_encoding(trim($res['Cause']),"utf-8", "gb2312"));
       $main_content=str_replace(",","，",mb_convert_encoding(trim($res['Main_Content']),"utf-8", "gb2312"));
       $df=mb_convert_encoding(trim($res['Draft']),"utf-8", "gb2312");
       $df=str_replace("：",":",$df);
       $draft=substr($df,0,strpos($df,":"));
       $tel=substr($df,strpos($df,":")+1,strlen($df)-strpos($df,":"));
       $notify_time=mb_convert_encoding(trim($res['Notify_Time']),"utf-8", "gb2312");
       $complete_time=mb_convert_encoding(trim($res['Complete_Time']),"utf-8", "gb2312");
       $linkman=str_replace(",","，",mb_convert_encoding(trim($res['linkman']),"utf-8", "gb2312"));
       $to_1=str_replace(",","，",mb_convert_encoding(trim($res['To_1']),"utf-8", "gb2312"));
       $to_2=str_replace(",","，",mb_convert_encoding(trim($res['To_2']),"utf-8", "gb2312"));
       $router=str_replace("/bn","\n",mb_convert_encoding(trim($res['Router']),"utf-8", "gb2312"));
       $file_path="";//重置调单文件
       $time =mb_convert_encoding($res['update_time'],"utf-8", "gb2312");
       $time= str_replace(" 一月 ","-01-",$time);
       $time= str_replace(" 二月 ","-02-",$time);
       $time= str_replace(" 三月 ","-03-",$time);
       $time= str_replace(" 四月 ","-04-",$time);
       $time= str_replace(" 五月 ","-05-",$time);
       $time= str_replace(" 六月 ","-06-",$time);
       $time= str_replace(" 七月 ","-07-",$time);
       $time= str_replace(" 八月 ","-08-",$time);
       $time= str_replace(" 九月 ","-09-",$time);
       $time= str_replace(" 十月 ","-10-",$time);
       $time= str_replace(" 十一月 ","-11-",$time);
       $time= str_replace(" 十二月 ","-12-",$time);

       //生成数组
       $reqdata = array(
               'Requisition_ID' => $req_id,
               'state' => $state,
               'type' => $type,
               'Cell_ID' => $cell_id,
               'org1_id'=>$org1_id,
               'us_login'=>$us_login,
               'Req_Mon'=>$mon,
               'Main_Send' =>$main_send,
               'Main_attemper' => $main_att,
                'Cause' => $cause,
               'Main_Content' => $main_content,
               'Draft' => $draft,
               'Tel' => $tel,
               'Notify_Time' => $notify_time,
               'Complete_Time' => $complete_time,
               'linkman' => $linkman,
               'To_1' => $to_1,
               'To_2' => $to_2,
               'Router' => $router,
               'File_Path' => $file_path,
               'update_time'=> $time,
            );
            $this->req->setReq($reqdata);

            echo $time."<br>";
       }
   }

?>
